﻿using IBLL;
using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class UserBLL : IUserBLL
    {
        public UserBLL(IEmployeeDAL<UserModel>dal)
        {
            Dal = dal;
        }

        public IEmployeeDAL<UserModel> Dal { get; }

        public Task<int> AddUser(UserModel user)
        {
            return Dal.AddAsync(user);
        }

        public List<UserModel> Users()
        {
            return Dal.GetAllAsync().ToList();
        }

        public dynamic UserShow(string? name, int tid)
        {
            var sql = from a in Dal.GetAllAsync()
                      select new
                      {
                          a.Id,
                          a.UserName,
                          a.tid,
                          a.Sex,
                          a.IDCard,
                          a.Phone,
                      };
            if (!string.IsNullOrEmpty(name)) 
            {
                sql = sql.Where(a => a.UserName.Contains(name));
            }
            if (tid > 0) 
            {
                sql = sql.Where(a => a.tid == tid);
            }
            return sql;
        }
    }
}
